import 'package:flutter/material.dart';
import 'package:flutter_app/app/models/subcategory.dart';
import 'package:flutter_app/resources/widgets/image.dart';
import 'package:nylo_framework/nylo_framework.dart';

class MovieView extends StatelessWidget {
  final SubcategorySubjects item;
  final double? width; // 可选：添加宽度参数
  final double aspectRatio; // 可选：宽高比

  const MovieView({
    super.key,
    required this.item,
    this.width,
    this.aspectRatio = 0.7, // 默认电影海报常见比例
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        routeTo("/search-movie", data: item.title ?? '');
      },
      child: SizedBox(
        width: width, // 控制卡片宽度
        child: Card(
          //elevation: 2, // 建议保留一些阴影
          elevation: 0,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(8),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              AspectRatio(
                aspectRatio: aspectRatio,
                child: ClipRRect(
                  borderRadius: const BorderRadius.vertical(
                    top: Radius.circular(8),
                  ),
                  child: ImageWidget(
                    imageUrl: item.cover ?? '',
                    fit: BoxFit.cover,
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.all(8),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      item.title ?? '无标题',
                      style: const TextStyle(
                        fontWeight: FontWeight.bold,
                      ),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    ),
                    const SizedBox(height: 4),
                    Text(
                      '评分: ${item.rate ?? '0.0'}', // 格式化评分
                      style: TextStyle(
                        color: Theme.of(context).primaryColor,
                        fontSize: 12,
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
